// Copyright (C) 2025 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

@import "common";
@import "./graph/graph.scss";
@import "./help.scss";
@import "./graph/node_box.scss";
@import "./node_styling_widgets.scss";
@import "./node_explorer.scss";
@import "./operations/operation_component.scss";
@import "./nodes/sources/slices_source.scss";
@import "./nodes/sources/table_source.scss";
@import "./nodes/sources/timerange_source.scss";
@import "./nodes/aggregation_node.scss";
@import "./nodes/modify_columns_node.scss";
@import "./table_list.scss";
@import "./widgets.scss";

.pf-query-builder-layout {
  // CSS variable for side panel width, used in both SCSS and TypeScript
  --pf-qb-side-panel-width: 60px;

  height: 100%;

  // SplitPanel's main section needs to have the grid layout
  .pf-split-panel__main {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    overflow: hidden;
  }

  .pf-qb-node-graph {
    grid-column: 1;
    overflow: auto;
    position: relative;
  }

  // Position the resize handle in the grid, but let the widget handle its own styling
  .pf-resize-handle {
    grid-column: 2;
  }

  .pf-qb-explorer {
    grid-column: 3;
    overflow: hidden;
    height: 100%;
    // Width is controlled by inline style for smooth resizing
  }

  .pf-qb-side-panel {
    grid-column: 4;
    width: var(--pf-qb-side-panel-width);
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0;
    border-left: 1px solid var(--pf-color-border);
    padding: 0;
    align-items: stretch;
    justify-content: flex-start;

    .pf-button {
      width: 100%;
      height: 60px;
      font-size: 20px;
      box-shadow: none;
      border: none;
      border-radius: 0;
      border-bottom: 1px solid var(--pf-color-border);

      &.pf-active {
        background-color: var(--pf-color-primary);
        color: var(--pf-color-text-on-primary);
      }
    }
  }

  .pf-qb-floating-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;

    .pf-button {
      width: 60px;
      height: 60px;
      font-size: 28px;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);

      &:hover {
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
        transform: scale(1.05);
      }
    }
  }

  .pf-qb-floating-controls-bottom {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;

    .pf-button {
      width: 40px;
      height: 40px;
      font-size: 20px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);

      &:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        transform: scale(1.05);
      }
    }
  }

  .pf-qb-floating-warning {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--pf-color-danger);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    cursor: pointer;

    &:hover {
      box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
      transform: scale(1.05);
    }

    .pf-qb-warning-icon {
      color: white;
      font-size: 28px;
    }
  }

  &.explorer-collapsed {
    .pf-resize-handle {
      display: none;
    }

    .pf-qb-explorer {
      border-left: none;
      overflow: hidden;
    }
  }
}

.pf-unselected-explorer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  height: 100%;
  padding: 24px;
  overflow-y: auto;

  // Center content when small, scroll when large
  &::before {
    content: "";
    flex-grow: 1;
  }

  &::after {
    content: "";
    flex-grow: 1;
  }
}

.pf-source-card {
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;

  .pf-source-card-clickable {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    transition: transform 0.1s ease;

    .pf-icon {
      font-size: 32px;
      color: var(--pf-color-primary);
      transition: color 0.1s ease;
    }

    h3 {
      margin: 0;
      font-size: 16px;
      font-weight: 500;
      transition: color 0.1s ease;
    }
  }

  &:hover .pf-source-card-clickable,
  &:focus-within .pf-source-card-clickable {
    transform: translateY(-2px);

    .pf-icon {
      color: var(--pf-color-accent);
    }

    h3 {
      color: var(--pf-color-accent);
    }
  }

  p {
    margin: 0;
    font-size: 13px;
    line-height: 1.4;
    color: var(--pf-color-text-muted);
    text-align: center;
  }

  .pf-source-card-hotkey {
    align-self: flex-end;
    margin-top: 4px;
  }
}

.pf-examples-modal {
  padding: 16px;
}

.pf-examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  max-width: 800px;
}

.pf-example-card {
  display: flex;
  flex-direction: column;
  gap: 8px;

  .pf-example-card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    transition: transform 0.1s ease;

    .pf-icon {
      font-size: 32px;
      color: var(--pf-color-primary);
      transition: color 0.1s ease;
    }

    h3 {
      margin: 0;
      font-size: 16px;
      font-weight: 500;
      transition: color 0.1s ease;
    }
  }

  &:hover .pf-example-card-content,
  &:focus-within .pf-example-card-content {
    transform: translateY(-2px);

    .pf-icon {
      color: var(--pf-color-accent);
    }

    h3 {
      color: var(--pf-color-accent);
    }
  }

  p {
    margin: 0;
    font-size: 13px;
    line-height: 1.4;
    color: var(--pf-color-text-muted);
    text-align: center;
  }
}

.pf-error-details {
  min-width: 300px;
  max-width: 500px;
  max-height: 400px;
  overflow-y: auto;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--pf-font-family-monospace, "Roboto Mono", monospace);
}
